﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Casemeet.Albums;
using VK.Comm;
using VK.Casemeet.Merchants;
using System.Web.Script.Serialization;

namespace VK.Casemeet.Web.ShopAdmin.Albums
{
    public partial class AlbumAdd : System.Web.UI.Page
    {
        public string imgUrl = "Null.jpg";

        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/ShopAdmin/Home.aspx"},
                new MapPath{ Text="相册列表",Url="/ShopAdmin/Albums/AlbumList.aspx"},
                new MapPath{ Text="新增相册",Url="#"}
            };

            if (!IsPostBack)
            {
                txtCreated.Text = DateTime.Now.ToString();
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            AlbumEntity album = LoadEntity();

            if (AlbumBLL.InsertAlbum(album) > 0)
            {
                Message.Msg(this.Page, CS.MsgAddSuccess, MessageType.Success);
                Util.ClearControl((this.Master as Site).contentBody.Controls);
                txtCreated.Text = DateTime.Now.ToString();
            }
            else
            {
                Message.Msg(this.Page, CS.MsgAddFailure, MessageType.Failure);
            }
        }

        protected AlbumEntity LoadEntity()
        {
            AlbumEntity album = new AlbumEntity();
            album.ObjectID = AdminBLL.GetSessionAdmin().ShopID;
            album.ObjectType = 1;
            album.Name = txtName.Text;
            album.Created = Util.ConverDateTime(txtCreated.Text);
            string[] imgUrlArray = new JavaScriptSerializer().Deserialize<string[]>(Util.GetFormString("hidImgUrlArray"));
            album.ImgUrllst = new List<string>(imgUrlArray);

            return album;
        }
    }
}